package com.bjsxt.web.controller;


import com.bjsxt.pojo.Users;
import com.bjsxt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    private UserService userService;
    @RequestMapping("/userLogin")
    public String userLogin(Users users, Model model, HttpServletRequest request){
        try{
            Users userlogin = this.userService.userlogin(users.getUsername(), users.getUserpwd());
            HttpSession session = request.getSession();
            session.setAttribute("user", userlogin);
        }catch (Exception e){
            e.printStackTrace();
            model.addAttribute("msg",e.getMessage());
            return "/login";
        }
        return "redirect:/index";
    }
}
